package com.cd826dong.clouddemo.service;

import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

public class HystrixCommandFailureService extends HystrixCommand<String> {

	private String name = "HystrixCommand";
	private RestTemplate restTemplate;

	
	
	public HystrixCommandFailureService(RestTemplate restTemplate, String name) {
		super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup")));
		this.restTemplate = restTemplate;
		this.name = name;
	}

	@Override
	protected String run() throws Exception {
		 return restTemplate.getForEntity("http://127.0.0.1:2100/hello/{name}", String.class, name).getBody();
	}
	
	@Override
	protected String getFallback() {
		return "fall back use HystrixCommand method," + name;
	}

}
